package com.dziennik.wedkarza;

import com.dziennik.wedkarza.database.DatabaseAdapter;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;


public class SlownikActivity extends Activity {
    
	private DatabaseAdapter DatabaseAdapter;
	private Button buttonZapisz;
	private EditText addNewRecord;
		
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.slownik_activity);
         
		initOpenDatabase();
		initUiElements();
		initButtonsOnClickListeners();
		
	}
	
	
private void initOpenDatabase() {
	DatabaseAdapter = new DatabaseAdapter(getApplicationContext());
	DatabaseAdapter.open();
}

private void initUiElements() {
	addNewRecord = (EditText) findViewById(R.id.addTextFisheriesCode);
	buttonZapisz = (Button) findViewById(R.id.buttonZapisz);
}



private void initButtonsOnClickListeners() {
    OnClickListener onClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.buttonZapisz: 
            	saveNewRecordSlownik();
            	break;
            default: break;
            }
        }
    };
    buttonZapisz.setOnClickListener(onClickListener);
     
}

private void saveNewRecordSlownik(){
    String codeFisheries = addNewRecord.getText().toString();
    Log.d("codeFisheries: ", codeFisheries);
  
    if(codeFisheries.equals("")){
    	addNewRecord.setError("Pole nie może być puste.");
    } else {
    	DatabaseAdapter.insertCodeFisheries(codeFisheries);
    	addNewRecord.setText("");
       
    }
   
}



}

		

